package org.example.memorystream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class MemoryStream1 {

    public static void main(String[] args) throws IOException {

        //init
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        //write data to memory
        outputStream.write(1);
        outputStream.write("hello".getBytes());

        //memory流可以不用关，自动也可
        outputStream.close();

        //怎样得到内存中的数据呢
        // 内存输出流本身就提供了方法，可以返回内存中数据的引用
        byte[] bytes = outputStream.toByteArray();

        String string = new String(bytes);

        System.out.println(string);
    }
}
